package com.scott.crm;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @author 黄后林
 * @version 1.0
 * @note
 * @date 2021-11-27 12:17:30
 */
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
    }

    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory){
        RedisTemplate redis = new RedisTemplate();
        redis.setConnectionFactory(connectionFactory);

        //在json对象中 所有的key都是字符传  value
        RedisSerializer stringSerializer = new StringRedisSerializer();
        redis.setKeySerializer(stringSerializer);

        Jackson2JsonRedisSerializer json = new Jackson2JsonRedisSerializer(Object.class);
        redis.setValueSerializer(json);




        return redis;
    }
}
